<template>
  <ProTable
    ref="tableRef"
    :fetchListApi="_systemCheckLog"
    :height="520"
    :columns="columns"
    row-key="id"
    :searchClassName="'card-container'"
  >
  </ProTable>
</template>

<script setup lang="tsx">
import { computed, ref } from 'vue';
import { Modal, RangePicker, Space } from 'ant-design-vue';
import dayjs, { Dayjs } from 'dayjs';
import { ProTable, ProTableProps } from '@/components/ProTable/index';
import { listToEnum } from '@/utils/utils';
import { systemCheckLog } from '@/api/device';
import { fetchDictsOfType } from '@/api/dict';

interface Props {
  pageData: any;
}
const props = defineProps<Props>();

const checkStatusEnum = ref<Record<string, any>>({});
const statusEnum = ref<Record<string, any>>({});
fetchDictsOfType(['sys_checkall_status', 'sys_check_status']).then(
  (res: any) => {
    const { sys_checkall_status, sys_check_status } = res.data;
    checkStatusEnum.value = listToEnum(
      sys_checkall_status,
      'dictValue',
      'dictLabel',
    );
    statusEnum.value = listToEnum(sys_check_status, 'dictValue', 'dictLabel');
  },
);

const _systemCheckLog = (params: any) => {
  params.code = props.pageData.code;
  params.startTime = params.date?.[0] || '';
  params.endTime = params.date?.[1] || '';
  return systemCheckLog(params);
};

const disabledDate = (val: any) => {
  const current = dayjs();
  return (val = current.endOf('day') && val > current.endOf('day'));
};

const columns = computed<ProTableProps['columns']>(() => [
  {
    title: '查询时间',
    dataIndex: 'date',
    hideInTable: true,
    customSearchRender(formState) {
      console.log(formState, 'formState');
      return (
        <RangePicker
          v-model:value={formState.date}
          format='YYYY-MM-DD HH:mm:ss'
          show-time
          default-time={['00:00:00', '23:59:59']}
          disabled-date={disabledDate}
          value-format='YYYY-MM-DD HH:mm:ss'
        />
      );
    },
  },
  {
    title: '检查时间',
    dataIndex: 'checkTime',
    hideInSearch: true,
  },
  {
    title: '检查总结果',
    dataIndex: 'checkStatus',
    valueEnum: checkStatusEnum.value,
    hideInSearch: true,
  },
  {
    title: '网络状态',
    dataIndex: 'networkStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '管理服务状态',
    dataIndex: 'manageStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '预警服务状态',
    dataIndex: 'mqttStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '烈度计状态',
    dataIndex: 'intensityStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '喇叭状态',
    dataIndex: 'hornStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '报警灯状态',
    dataIndex: 'lightStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '摄像头状态',
    dataIndex: 'cameraStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '对时服务状态',
    dataIndex: 'ntpStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '文件服务状态',
    dataIndex: 'fileStatus',
    hideInSearch: true,
    valueEnum: statusEnum.value,
  },
  {
    title: '检测类型',
    dataIndex: 'checkType',
    hideInSearch: true,
    customRender({ text }) {
      return text === 1 ? '自动检测' : '人工检测';
    },
  },
]);
</script>

<style lang="scss"></style>
